// TeacherInfomationPage.cpp : implementation file
//

#include "stdafx.h"
#include "SelectLesson.h"
#include "TeacherInfomationPage.h"
#include "TeacherInformationset.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTeacherInfomationPage property page

IMPLEMENT_DYNCREATE(CTeacherInfomationPage, CPropertyPage)

CTeacherInfomationPage::CTeacherInfomationPage() : CPropertyPage(CTeacherInfomationPage::IDD)
{
	//{{AFX_DATA_INIT(CTeacherInfomationPage)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CTeacherInfomationPage::~CTeacherInfomationPage()
{
}
BOOL CTeacherInfomationPage::OnCommand(WPARAM wParam, LPARAM lParam)
{
    SetModified(TRUE);
    return CPropertyPage::OnCommand(wParam, lParam);
}

void CTeacherInfomationPage::DoDataExchange(CDataExchange* pDX)
{
	TRACE("Entering CTeacherInfomationPage::DoDataExchange -- %d\n",
          pDX->m_bSaveAndValidate);
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTeacherInfomationPage)
	DDX_Control(pDX, IDC_LIST_TEACHER_INFORMATION, m_ListCtrl_TeacherInformation);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTeacherInfomationPage, CPropertyPage)
	//{{AFX_MSG_MAP(CTeacherInfomationPage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTeacherInfomationPage message handlers

BOOL CTeacherInfomationPage::OnSetActive() 
{
	m_ListCtrl_TeacherInformation.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_TRACKSELECT);
	m_ListCtrl_TeacherInformation.DeleteAllItems();
	
	m_database=new CDatabase;
	if(!m_database->Open(_T( "SelectLesson Registration" ),FALSE,FALSE, _T( "ODBC;" ),FALSE))
	{
		AfxMessageBox("ODBC Connection Faile!");
		return FALSE;
	}

	m_pTeacherset=new CTeacherInformationset(m_database);
	m_pTeacherset->Open(CRecordset::dynaset,_T("Select * from TeacherInformation"));
//	m_pTeacherset->Open();

	CString strTemp;
	int j=0;
//	m_pLessonset->MoveFirst();
	
	while( !m_pTeacherset->IsEOF() )
	{
		strTemp.Format(_T("%d"),m_pTeacherset->m_TeacherNumber);
		m_ListCtrl_TeacherInformation.InsertItem(j,(LPCTSTR)strTemp,0);
		strTemp.Format(_T("%s"),m_pTeacherset->m_TeacherName);
		m_ListCtrl_TeacherInformation.SetItemText(j,1,(LPCTSTR)strTemp);
		strTemp.Format(_T("%d"),m_pTeacherset->m_Sex);
		m_ListCtrl_TeacherInformation.SetItemText(j,2,(LPCTSTR)strTemp);
		strTemp.Format(_T("%d-%d-%d"),m_pTeacherset->m_Birthday.GetYear(),\
			m_pTeacherset->m_Birthday.GetMonth(),m_pTeacherset->m_Birthday.GetDay());
		m_ListCtrl_TeacherInformation.SetItemText(j,3,(LPCTSTR)strTemp);

		m_pTeacherset->MoveNext();
		j++;
	}
	return CPropertyPage::OnSetActive();
}

BOOL CTeacherInfomationPage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
    try
	{
		m_ListCtrl_TeacherInformation.InsertColumn(0,_T("TeacherNumber"),LVCFMT_LEFT,100,-1);
		m_ListCtrl_TeacherInformation.InsertColumn(1,_T("TeacherName"),LVCFMT_LEFT,100,-1);
		m_ListCtrl_TeacherInformation.InsertColumn(2,_T("Sex"),LVCFMT_LEFT,50,-1);
		m_ListCtrl_TeacherInformation.InsertColumn(3,_T("Birthday"),LVCFMT_LEFT,80,-1);
	}
	catch(CDBException* pEx)
	{
		pEx->ReportError();
	}
	return TRUE; 
}
